package leetcode_2501_2600;

public class LeeCode_2540 {
    public static void main(String[] args) {
        System.out.println(getCommon(new int[]{2, 4}, new int[]{1, 2}));
    }
    private static int getCommon(int[] nums1, int[] nums2) {
        int m = nums1.length, n = nums2.length;
        int l = 0, r = 0;
        while (l < m && r < n){
            if (nums1[l] == nums2[r]){
                return nums1[l];
            }else if (nums1[l] < nums2[r]){
                l++;
            }else {
                r++;
            }
        }
        return -1;
    }
}
